package com.dindang.ddm.mvp.ui.adapter.multitype;

import android.support.annotation.NonNull;
import android.support.constraint.ConstraintLayout;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dindang.ddm.R;
import com.dindang.ddm.mvp.model.entity.Work;
import com.dindang.ddm.mvp.ui.listener.AdapterListener;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class WorkViewBinder extends ItemViewBinder<Work, WorkViewBinder.ViewHolder> {

    AdapterListener mListener;
    public WorkViewBinder(AdapterListener listener) {
        mListener = listener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_worktable_work, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull Work work) {
        holder.mIvImage.setImageResource(work.getId());
        holder.mTvName.setText(work.getTitle());
        holder.mConstraintlayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mListener.onClick(holder.getAdapterPosition());
            }
        });
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ConstraintLayout mConstraintlayout;
        ImageView mIvImage;
        TextView mTvName;
        ViewHolder(View itemView) {
            super(itemView);
            mConstraintlayout = itemView.findViewById(R.id.constraintlayout);
            mIvImage = itemView.findViewById(R.id.iv_image);
            mTvName = itemView.findViewById(R.id.tv_name);
        }
    }
}
